package com.h6.crm.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.h6.crm.entity.SysUser;
import com.h6.crm.util.pojo.UserContext;

import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;

/**
 * 自动填充
 * 
 *
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "modifyTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "Deleted", Boolean.class, false);
        try {
            SysUser user = UserContext.currentUser();
            this.strictInsertFill(metaObject, "creater", String.class, user.getUserName());
            this.strictInsertFill(metaObject, "modify", String.class, user.getUserName());
        } catch (Exception e) {

        }

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "modifyTime", Date.class, new Date());
        try {
            this.strictUpdateFill(metaObject, "modify", String.class, UserContext.currentUser().getUserName());
        } catch (Exception e) {

        }

    }
}